<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Routing\Controller as BaseController;
use App\Http\Requests\StudentIndex;
use App\Http\Requests\StudentAdd;
use App\Http\Requests\StudentEdit;
use App\Models\Student;

class StudentController extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    /**
     * 学生列表
     * @param StudentIndex $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function index(StudentIndex $request)
    {
        $params = $request->validated();

        $student = new Student();

        $data = $student->getList($params);

        return response()->json($data);
    }

    /**
     * 学生添加
     * @param StudentAdd $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function save(StudentAdd $request)
    {
        $params = $request->validated();

        $student = new Student();

        $data = $student->add($params);

        return response()->json($data);
    }

    /**
     * 删除学生
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function del($id)
    {
        $student = new Student();

        $data = $student->del($id);

        return response()->json($data);
    }

    /**
     * 获取学生
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function get($id)
    {
        $student = new Student();

        $data = $student->get($id);

        return response()->json($data);
    }

    /**
     * 修改学生
     * @param StudentEdit $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function edit(StudentEdit $request)
    {
        $params = $request->validated();

        $student = new Student();

        $data = $student->edit($params);

        return response()->json($data);
    }
}
